#include <bits/stdc++.h>
#include<unordered_set>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;

/*思考
最大值和最小值和s
离谁近先去找谁，再去找另一个
一直等于最大值和最小值的距离加s到达最近的距离
*/

void solve() {
    int n, s,max,min,a[11];
    cin >> n >> s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    min = a[1];
    max = a[n];
    if (abs(max - s) > abs(s - min)) {//在中间
        cout << max - min + abs(s - min) << endl;
    }
    else{
        cout << max - min + abs(max - s) << endl;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}